package info.niwota.start;

import android.database.AbstractCursor;
import android.database.CursorWindow;

public class ArrayCursor extends AbstractCursor {
	private String[] mColumnNames = new String[2];
	private Object[][] mRows;

	public ArrayCursor(Object[] rows) {
		mColumnNames[0] = "_id";
		mColumnNames[1] = "object";
		int rowCount = rows.length;
		mRows = new Object[rowCount][2];
		for (int i = 0; i < rowCount; i++) {
			mRows[i][0] = i;
			mRows[i][1] = rows[i];
		}
	}

	@Override
	public void fillWindow(int position, CursorWindow window) {
		//
	}

	@Override
	public int getCount() {
		return mRows.length;
	}

	public boolean deleteRow() {
		return false;
	}

	@Override
	public String[] getColumnNames() {
		return mColumnNames;
	}

	@Override
	public byte[] getBlob(int columnIndex) {
		return (byte[]) mRows[mPos][columnIndex];
	}

	@Override
	public String getString(int columnIndex) {
		Object cell = mRows[mPos][columnIndex];
		return (cell == null) ? null : cell.toString();
	}

	@Override
	public short getShort(int columnIndex) {
		Number num = (Number) mRows[mPos][columnIndex];
		return num.shortValue();
	}

	@Override
	public int getInt(int columnIndex) {
		Number num = (Number) mRows[mPos][columnIndex];
		return num.intValue();
	}

	@Override
	public long getLong(int columnIndex) {
		Number num = (Number) mRows[mPos][columnIndex];
		return num.longValue();
	}

	@Override
	public float getFloat(int columnIndex) {
		Number num = (Number) mRows[mPos][columnIndex];
		return num.floatValue();
	}

	@Override
	public double getDouble(int columnIndex) {
		Number num = (Number) mRows[mPos][columnIndex];
		return num.doubleValue();
	}

	@Override
	public boolean isNull(int columnIndex) {
		return mRows[mPos][columnIndex] == null;
	}
	
	public Object getObject() {
		return mRows[mPos][1];
	}
}
